rm(list=ls())

load("TSCS_data.RData")

# Figure A.4 --------------------------------------------------------------

panel %>% filter(year == "2018") %>% 
  as.data.frame() ->
  panel_2019

pearsons_r <- cor(panel_2019$citizen_support,panel_2019$democratic_stock)

pdf(file = "fig_a4.pdf",width = 7,height = 6)

ggplot(panel_2019, aes(x = democratic_stock, y = citizen_support, label = country_name)) +
  geom_point() +
  geom_smooth(method = "gam") +
  geom_text_repel(aes(label = country_name), max.overlaps = getOption("ggrepel.max.overlaps", default = 10)) +
  xlab("Democratic Stock") +
  ylab("Citizen Support for Democracy") +
  annotate("text", label = paste("Pearson's r:", round(pearsons_r, 3)),
           x = min(panel_2019$democratic_stock), y = max(panel_2019$citizen_support), vjust = 1, hjust = -0.1)

dev.off()
